/*
 * Copyright 2022-2023 Advanced Micro Devices Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*

 * Filename: solo.hpp
 *
 * Description:
 * This network is used to find the same people from different image.
 *
 * Please refer to document "Xilinx_AI_SDK_User_Guide.pdf" for more details.
 */
#pragma once
#include <vitis/ai/proto/dpu_model_param.pb.h>

#include <memory>
#include <opencv2/core.hpp>
#include <vitis/ai/library/tensor.hpp>
#include "ndarray.hpp"
namespace vitis {
namespace ai {

/**
 * @brief Result with the Solo network.
 */
struct SoloResult {
  /// Width of input image.
  int width;
  /// Height of input image.
  int height;
  /// Double size of input image
  Ndarray<int> seg_masks;
  /// the labels
  Ndarray<int> cate_labels;
  /// the scores
  Ndarray<float> cate_scores;
};

/**
 * @brief Post-process of the solo neural network.
 * @param input_tensors A vector of all input-tensors in the network.
 *   Usage: input_tensors[input_tensor_index].
 * @param output_tensors A vector of all output-tensors in the network.
 *  Usage: output_tensors[output_index].
 * @return Struct of SoloResult.
 */
std::vector<SoloResult> solo_post_process_batch(
    const std::vector<vitis::ai::library::InputTensor>&
        input_tensors,
    const std::vector<vitis::ai::library::OutputTensor>&
        output_tensors, 
        const vitis::ai::proto::DpuModelParam& config,
        std::vector<std::vector<int>> size, std::vector<int> ind);
/**
 * @brief Post-process of the solo neural network in batch mode.
 * @param input_tensors A vector of all input-tensors in the network.
 *   Usage: input_tensors[input_tensor_index].
 * @param output_tensors A vector of all output-tensors in the network.
 *  Usage: output_tensors[output_index].
 * @return The vector of struct of SoloResult.
 */
SoloResult solo_post_process(
    const std::vector<vitis::ai::library::InputTensor>&
        input_tensors,
    const std::vector<vitis::ai::library::OutputTensor>&
        output_tensors, 
        const vitis::ai::proto::DpuModelParam& config,
        std::vector<int> size, std::vector<int> ind, size_t batch_ind);


template <class T>
static inline void pr(std::string name, Ndarray<T> array, size_t start, size_t end) {
  std::cout << "start: " << start << " end: " << " max_size: " << array.size() << std::endl;
  for (auto i = start; i < std::min(end, array.size()); i++) {
    std::cout << name << " ind: " << i << " value: " << array[i] << std::endl;
  }
}

}  // namespace ai
}  // namespace vitis
